﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
using Framework;
using BindType = ToLuaMenu.BindType;
using LuaInterface;

namespace FrameworkEditor
{
    public class ToLuaExportSettings
    {
        internal static BindType[] exportCsharpTypes
        {
            get
            {
                List<BindType> ret = new List<BindType>();
                ret.Add(new BindType(typeof(System.GC)));
                ret.Add(new BindType(typeof(UnityEngine.SystemInfo)));
                ret.Add(new BindType(typeof(UnityEngine.BoxCollider2D)));
                ret.Add(new BindType(typeof(UnityEngine.Rect)));
                ret.Add(new BindType(typeof(RectTransform)));
                ret.Add(new BindType(typeof(UnityEngine.ShaderVariantCollection)));
                ret.Add(new BindType(typeof(UnityEngine.Graphics)));
                ret.Add(new BindType(typeof(UnityEngine.Rendering.GraphicsTier)));

                //框架中的导出类
                ret.Add(new BindType(typeof(Framework.Logger)));
                ret.Add(new BindType(typeof(LuaFileUtils)));
                ret.Add(new BindType(typeof(FrameworkSettings)));
                ret.Add(new BindType(typeof(ResMgr)));
                ret.Add(new BindType(typeof(AssetItem))); 
                
                //lua mono
                ret.Add(new BindType(typeof(LuaMonoTools)));
                ret.Add(new BindType(typeof(LuaMonoBehaviour)));
                
                ret.Add(new BindType(typeof(Framework.UGUI.GuiHelper)));
                ret.Add(new BindType(typeof(Framework.UGUI.RectTrHelper)));
                ret.Add(new BindType(typeof(TransformHelper)));
                ret.Add(new BindType(typeof(GameObjectHelper)));
                ret.Add(new BindType(typeof(Framework.UGUI.ButtonWrap)));
                ret.Add(new BindType(typeof(Framework.UGUI.InputFieldWrap)));
                ret.Add(new BindType(typeof(Framework.UGUI.ScrollRectWrap)));
                ret.Add(new BindType(typeof(Framework.UGUI.SliderWrap)));
                ret.Add(new BindType(typeof(Framework.UGUI.ToggleWrap)));
                ret.Add(new BindType(typeof(Framework.UGUI.ToggleChecker)));
                ret.Add(new BindType(typeof(Framework.UGUI.UIClickListener)));
                ret.Add(new BindType(typeof(Framework.UGUI.UIDragListener)));
                ret.Add(new BindType(typeof(Framework.UGUI.UILongPressListener)));
                ret.Add(new BindType(typeof(Framework.UGUI.SingleImage)));
                
                //ugui 相关
                ret.Add(new BindType(typeof(UnityEngine.UI.Text)));
                ret.Add(new BindType(typeof(UnityEngine.UI.Image)));
                ret.Add(new BindType(typeof(UnityEngine.UI.RawImage)));
                ret.Add(new BindType(typeof(UnityEngine.CanvasGroup)));
                ret.Add(new BindType(typeof(UnityEngine.Canvas)));
                ret.Add(new BindType(typeof(UnityEngine.UI.Toggle)));
                ret.Add(new BindType(typeof(UnityEngine.UI.ToggleGroup)));
                ret.Add(new BindType(typeof(UnityEngine.UI.Slider)));
                ret.Add(new BindType(typeof(UnityEngine.UI.InputField)));
                ret.Add(new BindType(typeof(UnityEngine.Sprite)));
                ret.Add(new BindType(typeof(UnityHelper)));

                ret.Add(new BindType(typeof(UnityEngine.EventSystems.PointerEventData)));
                
                //工程中自定义的一些类
                foreach (var item in projExportTypes)
                {
                    ret.Add(new BindType(item));
                }
                return ret.ToArray();
            }
        }
        internal static DelegateType[] exportCsharpDelegateTypes
        {
            get
            {
                List<DelegateType> ret = new List<DelegateType>();
                //框架中的导出的回调类型
                //暂时还没有，有的话往后面加...

                //工程中自定义的一些回调类型导出
                foreach (var item in exportDelegates)
                {
                    ret.Add(new DelegateType(item));
                }
                return ret.ToArray();
            }
        }

        /// <summary>
        /// 获取项目中导出的C#类型
        /// </summary>
        /// <value></value>
        internal static Type[] projExportTypes
        {
            get
            {
                Type[] emptyRet = new Type[] { };
                Type projSetType = Type.GetType("ProjToLuaExportSettings");
                if (null == projSetType)
                {
                    return emptyRet;
                }
                FieldInfo fieldInfo = projSetType.GetField("customExportTypes");
                if (null == fieldInfo)
                {
                    return emptyRet;
                }
                return (Type[])fieldInfo.GetValue(null);
            }
        }

        /// <summary>
        /// 获取项目中导出的C#回调类型
        /// </summary>
        /// <value></value>
        internal static Type[] exportDelegates
        {
            get
            {
                Type[] emptyRet = new Type[] { };
                Type projSetType = Type.GetType("ProjToLuaExportSettings");
                if (null == projSetType)
                {
                    return emptyRet;
                }
                FieldInfo fieldInfo = projSetType.GetField("customDelegateExportTypes");
                if (null == fieldInfo)
                {
                    return emptyRet;
                }
                return (Type[])fieldInfo.GetValue(null);
            }
        }

        /// <summary>
        /// 项目需要过滤掉的方法
        /// </summary>
        /// <value></value>
        internal static string[] exportFuncFilters
        {
            get
            {
                string[] emptyRet = new string[] { };
                Type projSetType = Type.GetType("ProjToLuaExportSettings");
                if (null == projSetType)
                {
                    return emptyRet;
                }
                FieldInfo fieldInfo = projSetType.GetField("customFilterFuncs");
                if (null == fieldInfo)
                {
                    return emptyRet;
                }
                return (string[])fieldInfo.GetValue(null);
            }
        }
    }
}